from PyQt5.QtWidgets import QWidget, QToolTip, QApplication
from PyQt5.QtGui import QFont, QPainter, QPen
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *


class ChildWin(QWidget):
    def __init__(self, parent=None):
        super(ChildWin, self).__init__(parent)
        self.setWindowTitle('SubWin')

        self.setWindowFlags(Qt.FramelessWindowHint | Qt.BypassWindowManagerHint | Qt.Tool | Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setAttribute(Qt.WA_TransparentForMouseEvents, True) #点击穿透窗口
        self.wdt = QWidget()
        self.wdt.setAttribute(Qt.WA_TranslucentBackground)
        self.wdt.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.wdt.setObjectName("tipWaitingWindow_back")
        self.wdt.setStyleSheet("#tipWaitingWindow_back{background:rgba(0,0,0,0.8)}")

        self.layout = QGridLayout(self)
        self.layout.addWidget(self.wdt)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.text = ''
        self.dots = []
        self.dpi = 1

    def paintEvent(self, event):
        # 初始化绘图工具
        qp = QPainter()
        # 开始在窗口中绘制
        qp.begin(self)
        # 自定义画点方法
        self.drawPoint(qp)

        self.drawText(qp, event)

        # 结束在窗口中的绘制
        qp.end()

        self.setAttribute(Qt.WA_TransparentForMouseEvents, True)  # 点击穿透窗口

    def drawPoint(self, qp):
        pen = QPen()
        pen.setWidth(2*self.dpi)  # 线宽
        pen.setColor(Qt.red)  # 画线颜色
        pen.setStyle(Qt.SolidLine)  # 线的类型，如实线、虚线等
        pen.setCapStyle(Qt.FlatCap)  # 线端点样式
        pen.setJoinStyle(Qt.BevelJoin)  # 线的连接点样式

        # 设置笔的颜色
        qp.setPen(pen)

        cursize = 14*self.dpi
        cursize_harf = cursize/2
        for i in self.dots:
            qp.drawEllipse(int(i[0])-cursize_harf, int(i[1])-cursize_harf, cursize, cursize)

    def drawText(self, qp, event):
        if self.text:
            qp.setFont(QFont('Decorative', 30*self.dpi))
            qp.drawText(event.rect(), Qt.AlignCenter, self.text)

